package com.wn.system.controller;

import cn.hutool.core.util.RandomUtil;
import com.wn.common.exception.Assert;
import com.wn.common.result.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yellow Docter
 * @date 2024-09-03
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RefreshScope
@RestController
public class TestController {

    @GetMapping
    public String test(){
        return "test springboot";
    }

    @GetMapping("/test1")
    public Result test01(){
        return Result.ok("返回结果的测试...");
    }

    @GetMapping("/test2")
    public Result test02(){

        Assert.error("我这里是错误的异常....");

        return Result.ok("返回结果的测试...");
    }

    //http://localhost:9010/test/find/1000
    @GetMapping("/test/find/{id}")
    public String test03(@PathVariable("id") int id, String name){
        System.out.println("id = " + id);
        String s = RandomUtil.randomString(4);
        return  s + ":"+ id + ",name = "  + name;
    }

    @Value("${server.port}")
    private int port;

    //http://localhost:9010/test/get
    @GetMapping("/test/get")
    public String test04(){
        String s = RandomUtil.randomString(4);
        return  s + ":"+ ",port = "  + port;
    }

    @GetMapping("/test/token")
    public Result test01Token(){
        return Result.ok("返回结果的测试...token");
    }

    @GetMapping("/test/token2")
    public Result test01Token2(){
        return Result.ok("返回结果的测试...token");
    }

//    @Value("${wn.info}")
//    private String info;
//
//    @GetMapping("/test/info")
//    public Result testInfo(){
//        return Result.ok(info);
//    }

}
